package com.atguigu.thymeleaf.controller;


import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.UUID;

@Controller //页面跳转
//@RestController 不能页面跳转，只能返回json
public class HelloController {

    @GetMapping("/hello")
    public String  hello(HttpServletRequest request,
                         HttpSession session,
                         Model model,
                         Map map,
                         ModelMap modelMap){
        //model map modelMap是什么？ 底层都是一个BindingAwareModelMap
        model.addAttribute("model_val","Model6666");
        map.put("map_val","map666");
        modelMap.addAttribute("modelMapVal","modelMap666");
        request.setAttribute("requestVal","request6667");
        //setAttribute 设置指定标签属性的值
        //四大域对象 解决数据共享问题
        //page：页面签名放的后面能取出来
        //request： 一次请求期间都能在后面取出来
        //session： 同一次会话放的数据在，其他地方都能取出来
        //application： 在当前应用放的东西，所有会话都取得出来
        request.setAttribute("userName","张三");
        request.setAttribute("h1Id", UUID.randomUUID().toString().substring(0,4));
        request.setAttribute("mycolor","color:blue");



        List<String> list = Arrays.asList("郑爽", "刘德华", "张惠妹", "成龙");

        request.setAttribute("arrayList",list);


        request.setAttribute("age",18);


        session.setAttribute("hello","world");

        request.setAttribute("divContent","<span style='color:red'>张三666</span>");

        //thymeleaf 默认会在类路径下 templates找
        return "success";

    }
}
